
<template>
  <el-form >
    <el-form-item :label-width="formLabelWidth" label="审核结果:" >
      <el-select @change="audResultFlagChange"   v-model="Form.audResultFlag.value" placeholder="审核结果:">
        <el-option  v-for="(item,index) in Form.audResultFlag.options" :key="index"  :label="item.label" :value="item.value"></el-option>
      </el-select>
    </el-form-item>

  <el-form-item :label-width="formLabelWidth" label="退单原因是否正确：" >
      <el-select    v-model="Form.isRight.value" placeholder="退单原因是否正确：">
        <el-option  label="请选择" value="-1"></el-option>
        <el-option  label="不正确" value="0"></el-option>
        <el-option  label="正确" value="1"></el-option>
      </el-select>
    </el-form-item>

     <el-form-item  :label-width="formLabelWidth" label="是否录入错误：" >
      <el-select @change="isWrongChange"   v-model="Form.isWrong.value" placeholder="退单原因是否正确：">
        <el-option  label="请选择" value="-1"></el-option>
        <el-option  label="否" value="0"></el-option>
        <el-option  label="是" value="1"></el-option>
      </el-select>
    </el-form-item>

     <el-form-item v-show="Form.wrongReason.show" :label-width="formLabelWidth" label="原因类型：" >
      <el-select    v-model="Form.wrongReason.value" placeholder="原因类型：">
        <el-option  label="请选择" value="-1"></el-option>
        <el-option  label="客户错误" value="31740001"></el-option>
        <el-option  label="客户来单错误" value="31740002"></el-option>
      </el-select>
    </el-form-item>

   <el-form-item v-show="Form.audComment.show" :label-width="formLabelWidth" label="审核意见">
      <el-input  type="textarea" v-model="Form.audComment.value" placeholder="审核意见"></el-input>
    </el-form-item>


    <el-form-item class="btnDir">
      <el-button @click="onSubmit">执 行</el-button>
      <el-button @click="onCancel">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import OrderService from "@/api/order/OrderService.js";
import { mapState } from "vuex";
export default {
 components: {
	
  },
  computed: {
		...mapState("orders", ["orderItemList"]),
		...mapState("user", ["user"]),
	},
  async mounted(){
    
    if(this.CTOInfo instanceof Array){
      this.newCTOInfo = this.CTOInfo;
    }else{
      this.newCTOInfo = [this.CTOInfo];
    }
    
    if(this.newCTOInfo.length > 0){
      var orderItemIds="";
      var orderItemSeqs="";
      
      for(var i=0;i<this.newCTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.newCTOInfo[i].orderItemId;
           
           orderItemSeqs += this.newCTOInfo[i].orderItemSeq;
         }else{
            orderItemIds += ","+this.newCTOInfo[i].orderItemId;
            orderItemSeqs += ","+this.newCTOInfo[i].orderItemSeq;
         }
      }
      this.orderItemIds = orderItemIds;
      this.orderItemSeqs = orderItemSeqs;
      
      var scopeInfos=[]
      scopeInfos.push({scope:"orderTasks"});
      var custSoNumber = this.newCTOInfo[0].custSoNumber;
      var batchNbr =  this.newCTOInfo[0].batchNbr;
      var custId = this.newCTOInfo[0].custId;
      
      this.orderItemIds = orderItemIds;
      // const result=await CustOrderService.qryCustomerOrderDetail({custSoNumber,batchNbr,orderItemIds,custId,scopeInfos});
      // var  orderTask = result.orderDetails[0]['orderTasks'][0];
      // this.orderTask = orderTask;
      var custOrder = JSON.parse(localStorage.getItem("custOrder_select"));
      
      var result = {};

      var html_1 = [{value:"-1",label:"请选择"},{value:"1",label:"同意并停开"}];
      var html_2 = [{value:"-1",label:"请选择"},{value:"2",label:"同意并进行非正常变更"}];
      var html_3 = [{value:"-1",label:"请选择"},{value:"0",label:"不同意并驳回"}];
      var html_4 = [{value:"-1",label:"请选择"},{value:"0",label:"不同意并驳回"},{value:"2",label:"同意并进行非正常变更"}];
      var html_95 = [{value:"-1",label:"请选择"},{value:"1",label:"同意并停开"},{value:"0",label:"不同意并驳回"},{value:"2",label:"同意并进行非正常变更"}];
      var html_other = [{value:"-1",label:"请选择"},{value:"1",label:"同意并停开"},{value:"0",label:"不同意并驳回"},{value:"2",label:"同意并进行非正常变更"}];
      var html_idc = [{value:"-1",label:"请选择"},{value:"1",label:"同意并停开"},{value:"0",label:"不同意并驳回"},{value:"2",label:"同意并修改"}];
  
      //等传值
      var orderSourceId = custOrder.orderSourceId;
      this.custOrder = custOrder;
      var prodOfferId = this.newCTOInfo[0].prodOfferId;
      var taskId = "TACHE10020001";
     


       // 物联网需求 新增字段 如果是物联网审核退单 只能选择同意并做停开
   if (!this.isNull(orderSourceId) && "-1" == orderSourceId) {
     this.Form.audResultFlag.options = html_1;
   } else {
	   //云间高速业务 VPDN(L2TP、GRE),4008,综合VPN,综合VPN用户只有退单审核同意	                                                                                                                          //大数据三个产品
	   if ("11028853" == prodOfferId || "11028851" == prodOfferId || "10010047" == prodOfferId || "10010092" == prodOfferId || "10010046" == prodOfferId || "10010115" == prodOfferId||"24011116" == prodOfferId||"24011121" == prodOfferId||"24011124" == prodOfferId ||"24011035" == prodOfferId || "24011056" == prodOfferId) {
      
         this.Form.audResultFlag.options = html_1;
	   // 95业务 同意并停开和不同意并驳回
	   } else if("10010110" == prodOfferId){
        this.Form.audResultFlag.options = html_95;
		   //IDC
	   }else if("TACHE30010001"== taskId && "10010096,10010034,10010082,10010035,10010083,10010036,11027575,10010081".indexOf( prodOfferId)>-1){
       this.Form.audResultFlag.options = html_idc;
	   }  else {
		   if (!this.isNull(result) && result != "null") {
			   if ("1" == result) {
            this.Form.audResultFlag.options = html_1;
			   } else if ("2" == result) {
				   this.Form.audResultFlag.options = html_2;
			   } else if ("3" == result) {
            this.Form.audResultFlag.options = html_13
			   } else if ("4" == result) {
            this.Form.audResultFlag.options = html_4;
			   } else if ("0" == result) {
            this.Form.audResultFlag.options = html_other;
			   }else{
            this.Form.audResultFlag.options = html_other;
         }
		   } else {
			    this.Form.audResultFlag.options = html_other;
		   }
	   }
   }


    }else{
      this.Form.TASK_NAME.value = "";
    }
    this.Form.audResultFlag.value = "-1";
  },
  watch:{

  },
  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: [Object,Array],
			default: () => {
				return [];
			},
		},
  },
  data() {
    return {
      newCTOInfo:[],
      orderTask:{},
      custOrder:{},
      orderItemIds:"",
      orderItemSeqs:"",
      formLabelWidth:"120px",
     	Form:{
        audResultFlag:{
          options:[],
          value:"-1"
        },
        audComment:{
          value:"",
          show:true
        },
        isRight:{
          value:"-1"
        },
        isWrong:{
          value:"-1"
        },
        wrongReason:{
          value:"",
          show:false
        }

    }
    }
  },
  methods: {
    isWrongChange(e){
      if ("0" == e) {
          this.Form.wrongReason.show = true;
	
		} else {
	
       this.Form.wrongReason.show = false;
       this.Form.wrongReason.value = "-1";
		}
    },
    get95Check:function(){
			var flag ='true';
			var prodOfferId =this.newCTOInfo[0].prodOfferId;
			var orderItemIds =this.orderItemIds;
		
      //暂时不校验，数据库不好查询
			if(prodOfferId =='10010110'){
				// rtnMsg=ruleTrig.call("checkOrderDate4008", "ORDER_ITEM_IDS#"+orderItemIds);
				// if(rtnMsg > 0){
				// 	flag = 'false';
				// }
        // var param = {
        //  "interFaceType":"ORDER",
        //   "sqlId":"2021072002",
        //   "paramStr": "orderItemIds:"+orderItemIds
        // }
        // const result = await OrderService.executeSql(params);
        // var rtnMsg = result.meta.resList.executeSqlResps[0];
			}
			return flag ;
			
		},
    audResultFlagChange(e){
      
      if ("1" ==  e) {
       
          this.$message({
            showClose: true,
            message: "选择同意,该线路将停开!",
            type: "warn",
          });
          this.Form.audComment.show = false;
        } else {
         this.Form.audComment.show = true;
        }
    },
    isNull(val) {
      if (val == "NaN" || val == "null" || val == "undefined" || val == undefined || val=="") {
        return true;
      }else {
        return false;
      }
    },
    onCancel(){
      this.$emit("close")
    },
    async onSubmit(){
    
    
    if ("-1" == this.Form.audResultFlag.value) {
      
       this.$message({
            showClose: true,
            message: "审核结果不能为空!",
            type: "error",
          });
          return;
		} else if ((!"1" == this.Form.audResultFlag.value) && (this.isNull(this.Form.audComment.value))) {
        
       this.$message({
            showClose: true,
            message: "审核意见不能为空!",
            type: "error",
          });
           return;
		} else if ("-1" == this.Form.isRight.value) {
       
      this.$message({
            showClose: true,
            message: "退单原因是否正确不能为空!",
            type: "error",
          });
           return;
		} else if ("-1" == this.Form.isWrong.value) {
      
       this.$message({
            showClose: true,
            message: "是否录入不能为空!",
            type: "error",
          });
           return;
		} else if ("0" == this.Form.isWrong.value && ("-1" == this.Form.wrongReason.value)) {
      
      this.$message({
            showClose: true,
            message: "原因类型不能为空!",
            type: "error",
          });
           return;
		} else if('2'==this.Form.audResultFlag.value &&'false' == this.get95Check() ){
       
      this.$message({
            showClose: true,
            message: "要求完成日期四小时之前，才可以同意并进行非正常变更!",
            type: "error",
          });
			return ;
		}
    var audFlag = 0;
      if(this.Form.audResultFlag.value == "0"){
            audFlag = 0;
      }else {
        audFlag = 1;
      }

      var orderSourceId = this.custOrder.orderSourceId;
       var prodOfferId = this.newCTOInfo[0].prodOfferId;
       var statusCd = "401400";
       
       if(prodOfferId == "10010047"){
          if(this.user.regionCode == "100000"){
            statusCd = "401498";
          }else{
            statusCd = "401400";
          }
       }

       if(this.Form.audResultFlag.value == '0'){
         statusCd="200000";
       }

        var audFlag = "1";
        var audComment = "";
        
        if ("1"== this.Form.audResultFlag.value) {
				
          audFlag = "1";
          audComment = this.user.staffName+":"+this.$util.dateFormat(new Date(),"yyyy-MM-dd")+":同意并停开:"+this.Form.audComment.value;
				} else if ("2"==this.Form.audResultFlag.value) {
		
           audFlag = "2";
          audComment = this.user.staffName+":"+this.$util.dateFormat(new Date(),"yyyy-MM-dd")+":同意并进行非正常变更:"+this.Form.audComment.value;                 
				} else if ("0"==this.Form.audResultFlag.value) {
			
           audFlag = "2";
          audComment = this.user.staffName+":"+this.$util.dateFormat(new Date(),"yyyy-MM-dd")+":不同意并驳回:"+this.Form.audComment.value;                 
			
				}

       var param = {
         "orderItemIds":this.orderItemIds,
         "orderItemSeqs":this.orderItemSeqs,
         "custSoNumber":this.newCTOInfo[0].custSoNumber,
         "audResultFlag":this.Form.audResultFlag.value,
         "audFlag":audFlag,
         "statusCd":statusCd,
         "staffId":this.user.staffId,
         "staffName":this.user.staffName+"/"+this.user.staffPhone,
         "isRight":this.Form.isRight.value,
         "isWrong":this.Form.isWrong.value,
         "wrongReason":this.Form.wrongReason.value,
         "audComment":audComment,
         "type":"F",
         "custId":this.newCTOInfo[0].custId
       }
       

      var result = await CustOrderService.dealAuditBackOrder(param);
      
      if(result.meta.contractRoot.svcCont.resultCode == "0"){
         this.$message({
            showClose: true,
            message: result.meta.contractRoot.svcCont.resultMsg,
            type: "success",
          });
      }else{
        this.$message({
            showClose: true,
            message: result.meta.contractRoot.svcCont.resultMsg,
            type: "error",
          });
      }
      this.onCancel();
    }
  }
};
</script>

<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
</style>
